/*
 *  Copyright 2019-2020 Zheng Jie
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package me.zhengjie.modules.biz.rest;

import cn.hutool.core.convert.Convert;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import me.zhengjie.annotation.AnonymousAccess;
import me.zhengjie.annotation.Log;
import me.zhengjie.modules.biz.domain.HazardousChemicals;
import me.zhengjie.modules.biz.repository.HazardousChemicalsRepository;
import me.zhengjie.modules.biz.service.HazardousChemicalsService;
import me.zhengjie.modules.biz.service.dto.HazardousChemicalsDto;
import me.zhengjie.modules.biz.service.dto.HazardousChemicalsQueryCriteria;
import me.zhengjie.modules.utils.BaseResult;
import me.zhengjie.utils.ValidationUtil;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.boot.CommandLineRunner;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Timestamp;
import java.util.HashMap;
import java.util.Map;

/**
 * @author Admin
 * @website https://eladmin.vip
 * @date 2023-03-03
 **/
@RestController
@RequiredArgsConstructor
@Api(tags = "hazardous-chemicals管理")
@RequestMapping("/api/hazardousChemicals-v2")
public class HazardousChemicalsControllerV2 {

    private final HazardousChemicalsService hazardousChemicalsService;
    private final HazardousChemicalsRepository hazardousChemicalsRepository;

    @PostMapping
    @Log("新增hazardous-chemicals")
    @ApiOperation("新增hazardous-chemicals")
    public ResponseEntity<Object> createHazardousChemicals(@Validated @RequestBody HazardousChemicals resources) {
        try {
            HazardousChemicalsDto hazardousChemicalsDto = hazardousChemicalsService.create(resources, true);
            if (hazardousChemicalsDto.getName().equals("请勿重复入库同一物质！")) {
                return new ResponseEntity<>(new BaseResult(-1, "请勿重复入库同一物质！"), HttpStatus.OK);
            }
            return new ResponseEntity<>(new BaseResult(0, "入库成功"), HttpStatus.OK);
        } catch (Exception e) {
            return new ResponseEntity<>(new BaseResult(-1, e.getMessage()), HttpStatus.OK);
        }
    }

}
